package com.pproducto;

import java.sql.SQLException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

public class DBHelper extends OrmLiteSqliteOpenHelper {
	
	
	private static final String DATABASE_NAME = "basedato12.db";
	private static final int DATABASE_VERSION = 1;
	
	
	private Dao<Pproducto, Integer> pproductoDao;
	
	
	public DBHelper(Context context) {
	super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	
	@Override
	public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
	try {
	TableUtils.createTable(connectionSource, Pproducto.class);
	
	} catch (SQLException e) {
	throw new RuntimeException(e);
	}
	}
	
	
	@Override
	public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource,int oldVersion, int newVersion){
	  
		onCreate(db, connectionSource);
           }
	
	
	public Dao<Pproducto, Integer> getPproductoDao() throws SQLException {
	if (pproductoDao == null) {
	pproductoDao = getDao(Pproducto.class);
	}
	return pproductoDao;
	}
	
	
	
	@Override
	public void close() {
	super.close();
	pproductoDao = null;
	
	}
	
}



